﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ListenServer
{
    class Utils
    {
        /// <summary>
        /// 将图片以二进制流
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static byte[] SaveImage(String path)
        {
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); //将图片以文件流的形式进行保存
            BinaryReader br = new BinaryReader(fs);
            byte[] imgBytesIn = br.ReadBytes((int)fs.Length); //将流读入到字节数组中
            return imgBytesIn;
        }


        /// <summary>
        /// 现实二进制流代表的图片
        /// </summary>
        /// <param name="imgBytesIn"></param>
        public static void ShowImgByByte(byte[] imgBytesIn,string path)
        {

            string ImagePath = path;
            MemoryStream ms = new MemoryStream(imgBytesIn);
            Bitmap bmp = new Bitmap(ms);
            bmp.Save(ImagePath, ImageFormat.Bmp);
            ms.Close();
            //return NewImageName;

            //pictureBox1.Image = Image.FromStream(ms);
        }
    }
}
